package arisufascion.com.adapter;

import java.io.InputStream;
import java.util.List;

import com.androidquery.AQuery;

import android.app.Activity;
import android.app.DownloadManager.Query;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import arisufascion.com.R;
import arisufascion.com.constant.Constants;
import arisufascion.com.model.Categorie;

/**
 * 
 */

/**
 * @author kelvin
 * 
 */
public class CategoriesAdapter extends BaseAdapter {
	Activity mContext;
	public static final int ACTIVITY_CREATE = 10;
	private List<Categorie> categories;

	private Categorie categorie;
	private AQuery aq;

	public CategoriesAdapter(Activity c, List<Categorie> categories) {
		mContext = c;
		aq = new AQuery(c);
		this.categories = categories;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return categories.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		LayoutInflater inflator = mContext.getLayoutInflater();
		if (convertView == null) {
			holder = new ViewHolder();

			convertView = inflator.inflate(R.layout.row_categorie, null);

			holder.iv_categories = (ImageView) convertView
					.findViewById(R.id.iv_categories);

			holder.progressBar = (ProgressBar) convertView
					.findViewById(R.id.progressBar);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		categorie = categories.get(position);

		String url = String.format(Constants.SERVER_URL_IMAGES,
				String.valueOf(categorie.getImages()));

		aq.id(holder.iv_categories).progress(holder.progressBar)
				.image(url, true, true, 0, R.drawable.icon_logo);

		return convertView;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return categories.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return categories.get(position).getVirtuemart_category_id();
	}

	public static class ViewHolder {
		ImageView iv_categories;
		ProgressBar progressBar;
	}

}
